<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include::header"></head>
<body class="gray-bg">
	<div class="wrapper wrapper-content animated fadeInRight">
		<div class="row">
			<div class="col-sm-12">
				<div class="ibox float-e-margins">
					<div class="ibox-title">
						<h5>   </h5>
					</div>
					<div class="ibox-content">
						<form class="form-horizontal m-t" id="signupForm">
							<input type="hidden" name="roleId" th:value="${role.roleId}">
							 <input type="hidden" name="menuIds" id="m" >
							<div class="form-group">
								<label class="col-sm-3 control-label">角色名：</label>
								<div class="col-sm-8">
									<input  class="form-control"
										type="text" name="roleName" th:value="${role.roleName}">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">备注：</label>
								<div class="col-sm-8">
									<input  class="form-control"
										type="text" name="remark" th:value="${role.remark}" >
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">菜单权限：</label>
								<div class="col-sm-8">
									<div id="menuTree"></div>
								</div>
							</div>
							<div class="form-group">
								<div class="col-sm-8 col-sm-offset-3">
									<button type="button" class="btn btn-primary" onclick="save()">提交</button>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>
	<div th:include="include::footer"></div>
</body>
<script th:inline="javascript">
    $(function () {
        //生成树
        createTree();
        
    })
    function createTree(){

        $.ajax({
            url:'/sys/menu/tree/[[${role.roleId}]]',
            dataType:'json',
            type:'post',
            success:function (data) {
                create(data);
            }
            
        })
    }
    function create(data){
        $('#menuTree').jstree({
            core:{
                data:data
            },
            plugins:['checkbox']
        })
    }
    function save(){

        getMenuSelectIds();
        $.ajax({
            url: '/sys/role/doupdate',
            data: $('#signupForm').serialize(),
            dataType: 'json',
            type: 'post',
            success: function (data) {
                if (data.code == 200) {
                    //保存成功
                    parent.layer.close(parent.layer.getFrameIndex(window.name));
                    parent.reload();
                } else {
                    //保存失败
                    parent.layer.msg("修改失败", {icon: 2});
                }
            }
        })
    }
    function getMenuSelectIds(){
        var selected=$('#menuTree').jstree(true).get_selected();
        $('#m').val(selected);
    }
 </script>
</html>
